package com.test;

import com.core.Engine;
import com.core.R;
import com.core.R.id;
import com.core.R.layout;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.widget.FrameLayout;

public class MainActivity extends Activity
{
	private Engine engine;
	private FrameLayout viewContext;

	@Override
	protected void onCreate( Bundle savedInstanceState )
	{
		super.onCreate( savedInstanceState );
		setContentView( R.layout.activity_main );
		init();
	}

	private void init()
	{
		viewContext = ( FrameLayout ) findViewById( R.id.view_context );
		engine = Engine.create( this );
		engine.addInterface( "test", new Test() );
		viewContext.addView( engine.getWebView() );
	}

	@Override
	protected void onResume()
	{
		super.onResume();
		engine.getWebView().loadUrl( "file:///android_asset/test.html" );
		handler.postDelayed( new Runnable()
		{

			@Override
			public void run()
			{
				try
				{
					engine.execJsFuc( "alert", "'你好呀'" );
				}
				catch ( Exception e )
				{
					e.printStackTrace();
				}
			}
		}, 3000 );
	}

	@Override
	protected void onDestroy()
	{
		super.onDestroy();
		engine.destory();
	}

	private Handler handler = new Handler( Looper.getMainLooper() );
}
